package com.example.myapplication;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class MyService extends Service {

    MediaPlayer mediaPlayer;
    public MyService() {

        Log.d("zyy","MyService");

    }

    @Override
    public void onDestroy() {
        Log.d("zyy","MyService:onDestroy");
        mediaPlayer.stop();
        super.onDestroy();
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        Mybinder binder=new Mybinder();
        return binder;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d("zyy","MyService:onStratCommand");
//        mediaPlayer=MediaPlayer.create(this,R.raw.music);
//        mediaPlayer.start();
        return super.onStartCommand(intent, flags, startId);
    }

    public class Mybinder extends Binder{

        public void todo(){
            Log.d("zyy","MyService:mybinder todo");
            mediaPlayer=MediaPlayer.create(getApplicationContext(),R.raw.music);
            mediaPlayer.start();
        }
    }
}